/*
 * @Author: sundeqi
 * @Date: 2022-03-28 17:28:47
 * @LastEditors: sundeqi
 * @LastEditTime: 2022-03-30 19:01:56
 * @Description: Youtube直播入口
 */

import 'package:flutter/material.dart';
import 'base.dart';

class YoutubeIframe extends BaseWidget {
  final bool enableChat;
  const YoutubeIframe({Key? key, required String url, this.enableChat = false})
      : super(key: key, url: url);

  @override
  State<StatefulWidget> createState() => _YoutubeIframeState();
}

class _YoutubeIframeState extends BaseWidgetState<YoutubeIframe> {
  @override
  void onPageFinished(String src) {
    String videoId = widget.url.split('/').last;
    webControl?.evalRawJavascript('loadSrc(\'$videoId\',${widget.enableChat})');
  }

  @override
  void initState() {
    super.initState();
    LiveStreamController().start();
  }

  @override
  void dispose() {
    LiveStreamController().stop();
    super.dispose();
  }

  @override
  String get htmlPath =>
      'http://localhost:8080/packages/live_stream_iframe/assets/files/youtube.html';
}
